package com.qfedu.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qfedu.entity.AddressEntity;
import com.qfedu.entity.CustomerEntity;
import com.qfedu.entity.OrderDetailEntity;
import com.qfedu.entity.OrderEntity;
import com.qfedu.service.AddressService;
import com.qfedu.service.CustomerService;
import com.qfedu.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class OrderFormController {
    @Autowired
    private OrderService orderService;
@Autowired
private AddressService addressService;
@Autowired
private CustomerService customerService;
    @RequestMapping("/queryAllOrderHou.do")
    public String doQueryOrderHou(HttpServletRequest request,OrderEntity orderEntity){
        request.setAttribute("order",orderEntity);
        PageHelper.startPage(orderEntity.getPageNum(),orderEntity.getPageSize());
        List<OrderEntity> orderEntities = orderService.queryOrderById(orderEntity);
        PageInfo<OrderEntity> pageinfo = new PageInfo<>(orderEntities);
        request.setAttribute("pageinfo",pageinfo);
        return "order/order-list";
    }


    //查看详情
    @RequestMapping("/queryOrderDetail.do")
    public String doQueryOrderDetail(OrderEntity orderEntity,HttpServletRequest request){
        //商品信息
        List<OrderDetailEntity> orderDetailEntities = orderService.queryOrderDetail(orderEntity.getOid());
        //查询地址
        AddressEntity addressEntity = addressService.queryAddress(orderEntity.getAddressid());
        //查询用户
        CustomerEntity customerEntity = customerService.queryCustomer(orderEntity.getCid());

        request.setAttribute("orderdelist",orderDetailEntities);
        request.setAttribute("adres",addressEntity);
        request.setAttribute("custom",customerEntity);
        return "order/order-detail";
    }
}
